package com.ctshk.sapp.order.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.tour.dto.SeriesOrderReceiptListDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderReceiptListTouristDTO;
import com.ctshk.rpc.order.tour.dto.custom.CustomOrderReceiptDetailsPreviewDTO;
import com.ctshk.rpc.order.tour.dto.custom.CustomOrderReceiptInfoDTO;
import com.ctshk.rpc.order.tour.dto.custom.CustomOrderReceiptListCountDTO;
import com.ctshk.rpc.order.tour.dto.custom.CustomOrderReceiptListTouristDTO;
import com.ctshk.rpc.order.tour.req.SeriesOrderReceiptListReq;
import com.ctshk.rpc.order.tour.req.SeriesOrderReceiptListTouristReq;
import com.ctshk.rpc.order.tour.req.custom.*;
import com.ctshk.rpc.order.tour.service.ISeriesOrderReceiptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 系列团订单收据 前端控制器
 * </p>
 *
 * @author 谭响
 * @since 2021-02-01
 */
@Api(value="收据", tags="收据")
@RestController
@RequestMapping("/series/order/receipt")
public class SeriesOrderReceiptController extends BaseController {

    @DubboReference
    private ISeriesOrderReceiptService iSeriesOrderReceiptService;


    @ApiOperation(value = "列表", notes = "收據列表（收據管理）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收據列表", operDesc = "收據列表")
    @PostMapping("/list")
    public Result<CustomOrderReceiptListCountDTO> list(@RequestBody @Valid OrderReceiptListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return Result.success(iSeriesOrderReceiptService.list(req));
    }

    @ApiOperation(value = "查看收據", notes = "查看收據（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收據管理-查看", operDesc = "收據管理-查看")
    @PostMapping("/detail")
    public Result<CustomOrderReceiptInfoDTO> detail(@RequestBody @Valid CustomOrderReceiptDetailsIdReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.detail(req);
    }

    @ApiOperation(value = "打印收據-旅客列表", notes = "打印收據-旅客列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收據管理-打印收據", operDesc = "收據管理-打印收據")
    @PostMapping("/list-print")
    public Result<CustomOrderReceiptListTouristDTO> listPrint(@RequestBody @Valid CustomOrderReceiptListTouristReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return Result.success(iSeriesOrderReceiptService.listPrint(req));
    }

    @ApiOperation(value = "打印", notes = "销售收据预览-打印（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "銷售收據-打印", operDesc = "銷售收據-打印")
    @PostMapping("/print-receipt")
    public Result printReceipt(@RequestBody @Valid CustomOrderReceiptDetailsRePrintReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.printReceipt(req);
    }

    @ApiOperation(value = "打印整單收據", notes = "收據管理-打印整單收據（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "收據管理-打印整單收據", operDesc = "收據管理-打印整單收據")
    @PostMapping("/print-all")
    public Result printAll(@RequestBody @Valid OrderReceiptPrintAllReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.invalidAll(req);
    }

    @ApiOperation(value = "批量打印", notes = "批量打印（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "銷售收據-批量打印", operDesc = "銷售收據-批量打印")
    @PostMapping("/print-batch")
    public Result printBatch(@RequestBody @Valid CustomOrderReceiptPrintBatchReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.printBatch(req);
    }

    @ApiOperation(value = "收據作废", notes = "收據作废（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "收據管理-作廢", operDesc = "收據管理-作廢")
    @PostMapping("/invalid")
    public Result add(@RequestBody @Valid CustomOrderReceiptInvalidReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.invalid(req);
    }

    @ApiOperation(value = "重印收據", notes = "重印收據（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "收據管理-重印", operDesc = "收據管理-重印")
    @PostMapping("/re-print")
    public Result<CustomOrderReceiptDetailsPreviewDTO> rePrint(@RequestBody @Valid CustomOrderReceiptDetailsRePrintReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderReceiptService.rePrint(req);
    }

    @ApiOperation(value = "取消", notes = "销售收据预览-取消（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "銷售收據-取消", operDesc = "銷售收據-取消")
    @GetMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id) {
        return iSeriesOrderReceiptService.cancel(id,getCurrentUser(getRequest()).getId());
    }

}
